<?php

final class Front extends Controller {

    public $registry;

    public function __construct() {
        $this->registry = $this->registry = Registry::getInstance();
        
        $this->registry->get('load')->init_components();
        $this->registry->get('load')->init_modules();
    }

    public function dispatch($action) {
        $this->registry->hook->invokeAll('preaction');
        
        $exit_code = 1;
        while ($exit_code > 0) {
            list($exit_code, $controller) = $this->doAction($action);
            if ($exit_code > 0) {
                    $action = new Action('Error', array((string) $exit_code));
                    $this->registry->router->setCurrentAction($action);
            }
        }
        
        if ($controller instanceof AbstractModule) {
            $components = $this->registry->components;
            foreach ($components as $machine_name => $component) {
                if ($region = $controller->getStatusOfComponent($machine_name)) {
                    $this->registry->load->component($machine_name);
                    $action = new Action($component['main-controller'], array('region'=>$region));
                    $this->doAction($action);
                }
            }
        }
        $this->registry->hook->invokeAll('postaction');
    }
}

?>